<template>
  <div class="indexPage">
    <el-button @click="test()">测试接口响应</el-button>{{ text }}
    <hr />
    <el-button @click="test2()">测试错误</el-button>{{ text2 }}
    <hr />
  </div>
</template>

<script>
import textApi from "@/api/textApi";
export default {
  name: "indexPage",
  data() {
    return {
      text1: "",
      text2: "",
    };
  },
  mounted() {
    console.log(this.$store.getters.text);
  },
  computed: {
    text: {
      get() {
        return this.$store.getters.text;
      },
    },

  },
  methods: {
    test() {
      console.log(this.text);
      let newText = parseInt(this.text) + 1;

      this.$store.dispatch("setText", newText);
      textApi.getText().then((response) => {
        this.text = response.data + "2";
        this.$store.dispatch("setText", response.data);
        console.log(this.$store.getters.text);
      });
    },

    test2() {
      textApi.getText2().then((response) => {
        console.log(response);
        this.text2 = response.data;
      });
    },
  },
};
</script>

<style scoped></style>